package com.fangcang.redis.impl;

import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.fangcang.redis.RedisService;
import com.fangcang.redis.RedisUtil;
import com.fangcang.utils.LocalDateUtils;

@Service("redisService")
public class RedisServiceImpl  implements RedisService{
	private Logger log = LoggerFactory.getLogger(RedisServiceImpl.class);

		@Autowired
	    RedisUtil redisUtil;
		
	    public void getRedis(){
	    	log.info("hhms:datas keys size：" +redisUtil.hlen("hhms:datas"));
	    }
	    
	    
	    public void setBigDataToRedis() {
	    	Map<String, String> map = new HashMap<String, String>();
	    	for(int i=0; i<500000; i++) {
	    		map.put("hotel" + i, String.valueOf(LocalDateUtils.getLongTime(LocalDateTime.now())));
	    	}
	    	long startTime = System.currentTimeMillis();
	    	log.info("start set 1000000 size hash to Redis： " + startTime);
	    	redisUtil.hmset("HOTEL:MAPPING", map, 0);
	    	log.info("end set 1000000 size hash to Redis： " + (System.currentTimeMillis() - startTime));
	    	log.info("set hash to redis size :" + map.size());
	    }
		
}
